﻿@using Smartstore.Core.Identity
@using Smartstore.Web.Models.Identity

@model LoginModel

@{
    Assets.AppendTitleParts(T("PageTitle.Login"));
    Assets.AddMetaRobots();

    var registerUrl = Url.RouteUrl("Register");
    var returnUrl = Context.Request.Query["returnUrl"].ToString();
    if (returnUrl.HasValue())
    {
        registerUrl = Display.ModifyQueryString(registerUrl, "returnUrl=" + returnUrl.UrlEncode());
    }

    var currentUser = WorkContext.CurrentCustomer;
}

@{
    async Task SignInBlock()
    {
        <h3 class="text-center mb-4">
            @T("Account.Login.ReturningCustomer")
        </h3>

        <div asp-validation-summary="ModelOnly">@T("Account.Login.Unsuccessful")</div>

        <!-- SignIn Form -->
        <form asp-route="Login" asp-route-returnurl="@returnUrl" method="post" autocomplete="off">
            <input asp-for="CustomerLoginType" type="hidden" />
            @if (Model.CustomerLoginType == CustomerLoginType.Username)
            {
                <div class="form-floating mb-3">
                    <input asp-for="Username" class="username" autofocus="autofocus" autocomplete="username" placeholder="@Html.DisplayNameFor(x => x.Username)" />
                    <label asp-for="Username"></label>
                    <span asp-validation-for="Username"></span>
                </div>
            }
            else if (Model.CustomerLoginType == CustomerLoginType.Email)
            {
                <div class="form-floating mb-3">
                    <input asp-for="Email" class="email" autofocus="autofocus" autocomplete="email" placeholder="@Html.DisplayNameFor(x => x.Email)" />
                    <label asp-for="Email"></label>
                    <span asp-validation-for="Email"></span>
                </div>
            }
            else
            {
                <div class="form-floating mb-3">
                    <input asp-for="UsernameOrEmail" class="username" autofocus="autofocus" autocomplete="email username" placeholder="@Html.DisplayNameFor(x => x.UsernameOrEmail)" />
                    <label asp-for="UsernameOrEmail"></label>
                    <span asp-validation-for="UsernameOrEmail"></span>
                </div>
            }

            <div class="form-floating mb-3">
                <input asp-for="Password" sm-enable-visibility-toggle="false" class="password" autocomplete="current-password" placeholder="@Html.DisplayNameFor(x => x.Password)" />
                <button type="button" class="btn-toggle-pwd">
                    <i class="far fa-fw fa-eye-slash"></i>
                </button>
                <label asp-for="Password"></label>
                <span asp-validation-for="Password"></span>
            </div>

            <div class="form-group d-flex justify-content-between">
                <input asp-for="RememberMe" sm-switch="false" />
                <div class="forgot-password">
                    <a asp-route="PasswordRecovery" rel="nofollow">@T("Account.Login.ForgotPassword")</a>
                </div>
            </div>

            <captcha sm-enabled="Model.DisplayCaptcha" class="form-group" />

            <div class="form-group">
                <button type="submit" class="btn btn-primary btn-lg btn-block btn-login btn-prevent-multiclick">
                    @T("Account.Login.LoginButton")
                </button>
            </div>

            <div sm-suppress-if-empty-zone="external_auth_buttons" class="form-group external-auth-buttons mb-0">
                <div class="text-center text-uppercase mb-2">
                    - @T("Common.Or") -
                </div>
                <div class="vstack gap-2">
                    <zone name="external_auth_buttons" />
                </div>
            </div>

            <zone name="after_login_buttons" />
        </form>
    }

    async Task RegisterBlock()
    {
        <div class="page-info">
            @await Component.InvokeAsync("TopicBlock", new { systemName = "LoginRegistrationInfo", bodyOnly = true, isLead = true })
        </div>

        <div class="register-block">
            @if (Model.CheckoutAsGuest)
            {
                @await Component.InvokeAsync("TopicBlock", new { systemName = "CheckoutAsGuestOrRegister", bodyOnly = true })
                <div class="row sm-gutters">
                    <div class="col-sm-6 col-md-12 col-lg-6 pb-2 pb-lg-0">
                        <a class="btn btn-warning btn-lg btn-block register-button" href="@registerUrl">
                            @T("Account.Register.Button")
                        </a>
                    </div>
                    <div class="col-sm-6 col-md-12 col-lg-6">
                        <a class="btn btn-secondary btn-lg btn-block checkout-as-guest-button" asp-route="Checkout">
                            <span>@T("Account.Login.CheckoutAsGuest")</span>
                            <i class="fa fa-angle-right"></i>
                        </a>
                    </div>
                </div>
            }
            else
            {
                <div class="row">
                    <div class="col-12 col-lg-auto">
                        <a class="btn btn-warning btn-lg btn-block register-button" href="@registerUrl">
                            @T("Account.Register.Button")
                        </a>
                    </div>
                </div>
            }
        </div>
    }
}

<div class="page login-page">
	
    <div class="row mb-4">
        <div class="col-12 col-md-10 offset-md-1 col-xl-8 offset-xl-2">
            <div class="page-title">
                <h1>@T("Account.Login.Welcome")</h1>
            </div>
            <div class="card shadow-sm rounded-lg overflow-hidden">
                <div class="row">
                    <div class="col-12 col-lg-7 login-box">
                        <div class="p-3 p-xxl-4">
                            @{ await SignInBlock(); }
                        </div>
                    </div>
                    <div class="col-12 col-lg-5 register-box d-flex align-items-center">
                        <div class="p-3 p-xxl-4">
                            @{ await RegisterBlock(); }
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>